<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="节点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nodeName">
              <a-input :disabled="formDisabled" v-model="model.nodeName" placeholder="请输入节点名称"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="应收款金额（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentMoney">
              <a-input-number :disabled="formDisabled" :max="99999999" :min="0" v-model="model.paymentMoney" placeholder="请输入应收款金额" style="width: 100%"  disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="款项日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preCollectionDate">
              <j-date :disabled="formDisabled" placeholder="请选择款项日期" v-model="model.preCollectionDate"  style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="款项节点说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nodeDesc">
              <a-input :disabled="formDisabled" v-model="model.nodeDesc" placeholder="请输入款项节点说明"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联合同进度节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractNodeId">
              <!-- <a-input :disabled="formDisabled" v-model="model.contractNodeId" placeholder="请输入任务节点id"  ></a-input> -->
              <select-progress-payment-node-input ref="paymentInput" v-model="model.contractNodeId" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import SelectProgressPaymentNodeInput from '@/views/scy/components/SelectProgressPaymentNodeInput'

  export default {
    name: 'ErpProgressPaymentNodeForm',
    components: {
      SelectProgressPaymentNodeInput
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{},
        labelCol: {},
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          // nodeName: [ { required: true, message: '请输入节点名称!',whitespace:true} ],
          // paymentMoney: [
          //   { required: true, message: '请输入应收款金额!'},
          //   { pattern: /^[0-9]*[1-9][0-9]*$/, message: '请输入正整数!' }
          // ],
          // preCollectionDate: [ { required: true, message: '请选择款项日期!'} ],
          // nodeDesc: [ { required: true, message: '请输入款项节点说明!',whitespace:true} ],
          contractNodeId: [ { required: true, message: '请输入合同进度节点!', whitespace: true } ],
        },
        url: {
          add: "/api/erp/progress/erpProgressPaymentNode/add",
          edit: "/api/erp/progress/erpProgressPaymentNode/edit",
          queryById: "/api/erp/progress/erpProgressPaymentNode/queryById"
        },
        flag: false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      // this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add (mode) {
        console.log("==============",mode);
        this.$refs.paymentInput.getOld(mode.contractId)
        this.model = {}
      },
      edit (record) {
        console.log("==============record",record)
        this.$refs.paymentInput.getOld(record.contractId)
        this.model = Object.assign({}, record);
        this.$refs.paymentInput.initObj(record.contractNodeId)
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            this.$refs.paymentInput.selectedObj = []
            this.$refs.paymentInput.ids = []
            that.$emit('ok', this.model, this.flag);
          }
        })
      },
    }
  }
</script>
